<template style="width: 1000px;">
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <p>
              <a-divider orientation="left">企业基本信息</a-divider>
            </p>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['corpname', validatorRules.corpname]" placeholder="请输入公司名称" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="注册地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['registerAddress', validatorRules.registerAddress]" placeholder="请输入注册地址" ></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="税号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['nsrsbh', validatorRules.nsrsbh]" placeholder="请输入税号" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="注册时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择注册时间" v-decorator="['createTime']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="法定代表人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fddbr']" placeholder="请输入法定代表人" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="营业执照" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-image-upload isMultiple number="1" v-decorator="['yyzztp', validatorRules.yyzztp]" placeholder="营业执照" ></j-image-upload>
<!--              <j-image-upload isMultiple number="1" v-decorator="['csImg']" placeholder="证明图片" ></j-image-upload>-->
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="logo" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-image-upload isMultiple number="1" v-decorator="['logo', validatorRules.logo]" placeholder="logo" ></j-image-upload>
              <!--              <j-image-upload isMultiple number="1" v-decorator="['csImg']" placeholder="证明图片" ></j-image-upload>-->
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="邀请二维码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-image-upload isMultiple number="1" v-decorator="['inviteQrCode']" placeholder="邀请二维码" disabled="disabled"></j-image-upload>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24">
            <p>
              <a-divider orientation="left">项目联系人信息</a-divider>
            </p>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="联系人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lxrxm', validatorRules.lxrxm]" placeholder="请输入联系人姓名" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="联系人手机" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lxrsj', validatorRules.lxrsj]" placeholder="请输入联系人手机" ></a-input>
            </a-form-item>
          </a-col>
        </a-row>


        <a-row>
          <a-col :span="24">
            <p>
              <a-divider orientation="left">开票信息</a-divider>
            </p>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['corpname', validatorRules.corpname]" placeholder="请输入公司名称" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="纳税人识别号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['nsrsbh', validatorRules.nsrsbh]" placeholder="请输入纳税人识别号" ></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="开户行" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['khh', validatorRules.khh]" placeholder="请输入开户行" ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="对公账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dgzh', validatorRules.dgzh]" placeholder="请输入对公账号" ></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="注册地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['registerAddress', validatorRules.registerAddress]" placeholder="请输入注册地址" ></a-input>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24">
            <p>
              <a-divider orientation="left">快递地址信息</a-divider>
            </p>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-item label="办公地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['officeAddress', validatorRules.officeAddress]" placeholder="请输入办公地址" ></a-input>
            </a-form-item>
          </a-col>
        </a-row>

          <a-row>
            <a-col :span="24">
              <p>
                <a-divider orientation="left">综合服务费费率信息</a-divider>
              </p>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="20">
              <a-form-item label="平台综合服务费费率" :labelCol="{ xs: { span: 24 }, sm: { span: 6 }}" :wrapperCol="{xs: { span: 24 },sm: { span: 3 }}">
                <a-input-number v-decorator="['ptzhfwfl', validatorRules.ptzhfwfl]" placeholder="例如1.88" style="width: 80%"/>
                <span> %</span>
              </a-form-item>
            </a-col>
            <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
              <a-button @click="submitForm">提 交</a-button>
            </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'
  import JDate from '@/components/jeecg/JDate'
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import ImagCropper from "@views/jeecg/ImagCropper";

  export default {
    name: 'LhygCorpinfoForm',
    components: {
      ImagCropper,
      JFormContainer,
      JDate,
      JImageUpload,
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          corpname: {
            rules: [
              { required: true, message: '请输入公司名称!'},
            ]
          },
          registerAddress: {
            rules: [
              { required: false, message: '请输入注册地址!'},
            ]
          },
          officeAddress: {
            rules: [
              { required: true, message: '请输入办公地址!'},
            ]
          },
          nsrsbh: {
            rules: [
              { required: true, message: '请输入纳税人识别号!'},
            ]
          },
          sh: {
            rules: [
              { required: true, message: '请输入税号!'},
            ]
          },
          khh: {
            rules: [
              { required: true, message: '请输入开户行!'},
            ]
          },
          dgzh: {
            rules: [
              { required: true, message: '请输入对公账号!'},
            ]
          },
          lxrxm: {
            rules: [
              { required: true, message: '请输入联系人姓名!'},
            ]
          },
          lxrsj: {
            rules: [
              { required: true, message: '请输入联系人手机!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
            ]
          },
          yx: {
            rules: [
              { required: true, message: '请输入邮箱!'},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
            ]
          },
          yyzztp: {
            rules: [
              { required: true, message: '请输入营业执照图片!'},
            ]
          },
          logo: {
            rules: [
              { required: true, message: '请输入logo图片!'},
            ]
          },
          ptzhfwfl: {
            rules: [
              { required: true, message: '请输入平台综合服务费费率!'},
              { pattern: /^(\d{1,2}(\.[0-9]{1,2})?)$|^100$/, message: '请输入平台综合服务费费率,例如1.88%,请填写1.88!'},
            ]
          },
        },
        url: {
          add: "/corpinfo/lhygCorpinfo/add",
          edit: "/corpinfo/lhygCorpinfo/edit",
          queryById: "/corpinfo/lhygCorpinfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createTime','corpname','registerAddress','officeAddress','nsrsbh','sh','khh','dgzh','lxrxm','lxrsj','yx','yyzztp','htbh','status','fddbr','bwtrxm','bwtrsfzh','bwtrzw','bwtrsjh','bwtrsfzzmz','bwtrsfzfmz','ptzhfwfl','csImg','logo','inviteQrCode'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createTime','corpname','registerAddress','officeAddress','nsrsbh','sh','khh','dgzh','lxrxm','lxrsj','yx','yyzztp','htbh','status','fddbr','bwtrxm','bwtrsfzh','bwtrzw','bwtrsjh','bwtrsfzzmz','bwtrsfzfmz','ptzhfwfl','csImg','logo','inviteQrCode'))
      },
    }
  }
</script>